<?php
// +----------------------------------------------------------------------
// | 跃飞 [ 将来的你一定会感激现在奋斗的自己 ]
// +----------------------------------------------------------------------
// | Author: 钟贵廷
// +----------------------------------------------------------------------
// | Author URI: https://git.oschina.net/yeafy
// +----------------------------------------------------------------------
// | weChat:gt845272922  qq:845272922
// +----------------------------------------------------------------------


namespace app\yeafy\observer\demo2;


class Order implements ISubject
{
    private  $state;
    private $observer = [];

    public function registerObserver(IObserver $observer)
    {
        $this->observer[] = $observer;
    }

    public function removeObserver(IObserver $observer)
    {
        foreach ($this->observer as $k=>$v)
        {
            if($v == $observer)
            {
                unset($this->observer[$k]);
            }
        }
    }

    public function notifyObserver()
    {
        foreach ($this->observer as $k=>$v)
        {
            $v->sendEmail($this->getState());
        }
    }

    /**
     * @return mixed
     */
    public function getState()
    {
        return $this->state;
    }

    /**
     * @param mixed $state
     */
    public function setState($state)
    {
        $this->state = $state;
        $this->notifyObserver();
    }
    
    

}